package com.it2297.view;

import javax.swing.JPanel;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JTextField;
import javax.swing.JRadioButton;
import javax.swing.JComboBox;
import javax.swing.JSpinner;
import javax.swing.JButton;

import com.it2297.controller.CustomerController;
import com.it2297.main.UserApp;
import com.it2297.model.User;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JPasswordField;
import java.awt.Color;

import java.text.DateFormat;
import java.text.SimpleDateFormat;



public class ViewCustomerView extends JPanel {
	private final CustomerController vcc = new CustomerController(this);
	
	private final JLabel lblMyPage = new JLabel("My Page ");
	private final JLabel lblName = new JLabel("Name");
	private final JLabel lblGender = new JLabel("Gender");
	private final JLabel lblRace = new JLabel("Race");
	private final JLabel lblIdentificationNumber = new JLabel("Identification Number");
	private final JLabel lblDateOfBirth = new JLabel("Date Of Birth");
	private final JLabel lblEmail = new JLabel("Email");
	private final JLabel lblContactNumber = new JLabel("Contact Number ");
	private final JLabel lblAddress = new JLabel("Address");
	private final JLabel lblCountryOfBirth = new JLabel("Country Of Birth");
	private final JTextField name_TF = new JTextField();
	private final JTextField nric_TF = new JTextField();
	private final JTextField email_TF = new JTextField();
	private final JTextField phone_TF = new JTextField();
	private final JTextField address_TF = new JTextField();
	private final JTextField cob_TF = new JTextField();
	private final JTextField dob_TF = new JTextField();
	private final JTextField race_TF = new JTextField();
	private final JTextField gender_TF = new JTextField();
	private final JLabel lblPassword = new JLabel("Password");
	private final JPasswordField password_TF = new JPasswordField();
	private final JButton btnNewButton = new JButton("Refresh");

	/**
	 * Create the panel.
	 */
	public ViewCustomerView() {
		
		gender_TF.setEditable(false);
		gender_TF.setBounds(197, 104, 86, 24);
		gender_TF.setColumns(10);
		gender_TF.setText(UserApp.getCurrentUser().getGender());
		race_TF.setEditable(false);
		race_TF.setBounds(197, 158, 86, 23);
		race_TF.setColumns(10);
		race_TF.setText(UserApp.getCurrentUser().getEthnic());
		dob_TF.setEditable(false);
		dob_TF.setBounds(197, 275, 86, 24);
		dob_TF.setColumns(10);
		
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String dob = df.format(UserApp.getCurrentUser().getDob());
		dob_TF.setText(dob);
		
		
		//dob_TF.setText(UserApp.getCurrentUser().getDob());
		cob_TF.setEditable(false);
		cob_TF.setBounds(197, 547, 86, 20);
		cob_TF.setColumns(10);
		cob_TF.setText(UserApp.getCurrentUser().getCountryOfBirth());
		address_TF.setEditable(false);
		address_TF.setBounds(197, 438, 196, 70);
		address_TF.setColumns(10);
		address_TF.setText(UserApp.getCurrentUser().getAddress());
		phone_TF.setEditable(false);
		phone_TF.setBounds(197, 390, 152, 24);
		phone_TF.setColumns(10);
		phone_TF.setText(UserApp.getCurrentUser().getPhone());
		email_TF.setEditable(false);
		email_TF.setBounds(198, 333, 215, 24);
		email_TF.setColumns(10);
		email_TF.setText(UserApp.getCurrentUser().getEmail());
		nric_TF.setText("S7893421D");
		nric_TF.setEditable(false);
		nric_TF.setBounds(200, 215, 152, 24);
		nric_TF.setColumns(10);
		nric_TF.setText(UserApp.getCurrentUser().getNric());
		name_TF.setEditable(false);
		name_TF.setBounds(197, 57, 196, 24);
		name_TF.setColumns(10);
		name_TF.setText(UserApp.getCurrentUser().getName());

		initGUI();
	}
	private void initGUI() {
		setLayout(null);
		lblMyPage.setFont(new Font("Arial", Font.BOLD, 15));
		lblMyPage.setBounds(32, 11, 140, 35);
		
		add(lblMyPage);
		lblName.setFont(new Font("Arial", Font.PLAIN, 12));
		lblName.setBounds(58, 57, 46, 24);
		add(lblName);
		lblGender.setFont(new Font("Arial", Font.PLAIN, 12));
		lblGender.setBounds(58, 105, 46, 24);
		
		add(lblGender);
		lblRace.setFont(new Font("Arial", Font.PLAIN, 12));
		lblRace.setBounds(58, 158, 46, 24);
		
		add(lblRace);
		lblIdentificationNumber.setFont(new Font("Arial", Font.PLAIN, 12));
		lblIdentificationNumber.setBounds(58, 216, 132, 24);
		
		add(lblIdentificationNumber);
		lblDateOfBirth.setFont(new Font("Arial", Font.PLAIN, 12));
		lblDateOfBirth.setBounds(58, 276, 89, 24);
		
		add(lblDateOfBirth);
		lblEmail.setFont(new Font("Arial", Font.PLAIN, 12));
		lblEmail.setBounds(58, 334, 46, 24);
		
		add(lblEmail);
		lblContactNumber.setFont(new Font("Arial", Font.PLAIN, 12));
		lblContactNumber.setBounds(58, 391, 103, 24);
		
		add(lblContactNumber);
		lblAddress.setFont(new Font("Arial", Font.PLAIN, 12));
		lblAddress.setBounds(58, 450, 46, 24);
		
		add(lblAddress);
		lblCountryOfBirth.setFont(new Font("Arial", Font.PLAIN, 12));
		lblCountryOfBirth.setBounds(58, 547, 89, 18);
		
		add(lblCountryOfBirth);
		
		add(name_TF);
		
		add(nric_TF);
		
		add(email_TF);
		
		add(phone_TF);
		
		add(address_TF);
		
		add(cob_TF);
		
		add(dob_TF);
		
		add(race_TF);
		
		add(gender_TF);
		lblPassword.setFont(new Font("Arial", Font.PLAIN, 12));
		lblPassword.setBounds(58, 608, 89, 24);
		
		add(lblPassword);
		password_TF.setFont(new Font("Arial", Font.PLAIN, 12));
		password_TF.setEditable(false);
		password_TF.setBounds(197, 611, 132, 20);
		
		password_TF.setText(UserApp.getCurrentUser().getPassword());

		add(password_TF);
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				gender_TF.setText(UserApp.getCurrentUser().getGender());
				race_TF.setText(UserApp.getCurrentUser().getEthnic());

				DateFormat df = new SimpleDateFormat("MM/dd/yyyy");
				String dob = df.format(UserApp.getCurrentUser().getDob());
				dob_TF.setText(dob);

				cob_TF.setText(UserApp.getCurrentUser().getCountryOfBirth());
				phone_TF.setText(UserApp.getCurrentUser().getPhone());
				address_TF.setText(UserApp.getCurrentUser().getAddress());
				email_TF.setText(UserApp.getCurrentUser().getEmail());
				nric_TF.setText(UserApp.getCurrentUser().getNric());
				name_TF.setText(UserApp.getCurrentUser().getName());
				password_TF.setText(UserApp.getCurrentUser().getPassword());
			}
		});
		btnNewButton.setFont(new Font("Arial", Font.PLAIN, 12));
		btnNewButton.setBounds(324, 16, 89, 24);
		
		add(btnNewButton);
	}

	public String getNric() {
		return nric_TF.getText();
	}
	
	public void setEmail(String email) {
		email_TF.setText(email);
	}
	public void setAddress(String address) {
		address_TF.setText(address);
	}
	public void setPhone(String phone) {	
		phone_TF.setText(phone);

	}
	public void setPassword(String password) {
		password_TF.setText(password);
	
	}
	public void setNric(String nric) {	
		nric_TF.setText(nric);

	}
	public void setName(String name) {	
		name_TF.setText(name);

	}
	
	public void setGender(String gender){
		gender_TF.setText(gender);
	}
}
